package com.ruoyi.web.controller.dgw;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dgw.domain.Subsidies;
import com.ruoyi.dgw.service.ISubsidiesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 补贴发放Controller
 * 
 * @author ruoyi
 * @date 2021-11-23
 */
@RestController
@RequestMapping("/dgw/subsidies")
public class SubsidiesController extends BaseController
{
    @Autowired
    private ISubsidiesService subsidiesService;

    /**
     * 查询补贴发放列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:subsidies:list')")
    @GetMapping("/list")
    public TableDataInfo list(Subsidies subsidies)
    {
        startPage();
        List<Subsidies> list = subsidiesService.selectSubsidiesList(subsidies);
        return getDataTable(list);
    }

    /**
     * 导出补贴发放列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:subsidies:export')")
    @Log(title = "补贴发放", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Subsidies subsidies)
    {
        List<Subsidies> list = subsidiesService.selectSubsidiesList(subsidies);
        ExcelUtil<Subsidies> util = new ExcelUtil<Subsidies>(Subsidies.class);
        return util.exportExcel(list, "补贴发放数据");
    }

    /**
     * 获取补贴发放详细信息
     */
    @PreAuthorize("@ss.hasPermi('dgw:subsidies:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(subsidiesService.selectSubsidiesById(id));
    }

    /**
     * 新增补贴发放
     */
    @PreAuthorize("@ss.hasPermi('dgw:subsidies:add')")
    @Log(title = "补贴发放", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Subsidies subsidies)
    {
        return toAjax(subsidiesService.insertSubsidies(subsidies));
    }

    /**
     * 修改补贴发放
     */
    @PreAuthorize("@ss.hasPermi('dgw:subsidies:edit')")
    @Log(title = "补贴发放", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Subsidies subsidies)
    {
        return toAjax(subsidiesService.updateSubsidies(subsidies));
    }

    /**
     * 删除补贴发放
     */
    @PreAuthorize("@ss.hasPermi('dgw:subsidies:remove')")
    @Log(title = "补贴发放", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(subsidiesService.deleteSubsidiesByIds(ids));
    }
}
